package cn.highedu.coolshark_product.security;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

/**
 * 测试用户详情服务类
 */
// @Component
@Slf4j
public class TestUserDetailsService implements UserDetailsService {
    /**
     * 根据用户名查询用户详情
     * @param username 用户名
     * @return 用户详情
     * @throws UsernameNotFoundException 用户名未找到异常
     */
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        if (username.equals("tom")) {
            log.debug("用户名正确");
            return new TestUserDetail();
        }
        throw new UsernameNotFoundException("用户名" + username + "不存在");
    }
}
